package com.my.exception;

import com.my.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice  // 作用用来捕获控制器controller层的所有异常
// @ControllerAdvice   等价
// @ResponseBody       等价
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public Result doException (Exception e) {
        log.error(e.getMessage());
        return Result.error("出错了,请联系管理员!");
    }
}
